package com.whmskj.xjlhsc.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import org.springframework.web.bind.annotation.RestController;
import com.google.common.base.Predicates;

@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class SwaggerConfig {

    // energymanage 分组
    @Bean
    public Docket energymanageApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("energymanage")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.whmskj.xjlhsc.mobie.energymanage"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo("移动端-能耗管理(energymanage)"));
    }

    // ProductionManagement 分组
    @Bean
    public Docket productionManagementApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("ProductionManagement")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.whmskj.xjlhsc.mobie.ProductionManagement"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo("移动端-生产管理(ProductionManagement)"));
    }

    // personnelFile 分组
    @Bean
    public Docket personnelApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("personnelFile")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.whmskj.xjlhsc.mobie.personnelFile.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo("移动端-人员档案(personnelFile)"));
    }

    private ApiInfo apiInfo(String title) {
        return new ApiInfoBuilder()
                .title("XJLHSC 接口文档 - " + title)
                .description("基于 Knife4j + Springfox 生成")
                .version("1.0.0")
                .build();
    }
}

